/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.colswe.testingProject.control;

import org.colswe.testingProject.entity.Person;

/**
 *
 * @author Andrés Esteban Paez Torres
 * @version 1.0
 */
public class AuthenticationControl {

    public String userRole(Person person) {
        Control<Person> controlPerson = new PersonControl();
        Person other;
        other = controlPerson.read(person);
        if (person.getPassword().equals(other.getPassword())) {
            return other.getRole();
        }
        return null;
    }

    boolean userNameFormatValidation(String userName) {
        return !(userName.contains(" "));
    }

    boolean userNameLengthValidation(String userName) {
        return (userName.length() <= 20 && userName.length() >= 5);
    }

    boolean userNameUniquenessValidation(Person person) {
        Control<Person> controlPerson = new PersonControl();
        Person other;
        other = controlPerson.read(person);
        return (other == null);
    }

    boolean passwordLengthValidation(String password) {
        return (password.length() <= 30 && password.length() >= 5);
    }

    boolean passwordFormatValidation(String password) {
        return password.matches("[[[A-Z]+][[a-z]+][[0-9]+]]+");
    }

    public boolean passwordConfirmationValidation(String password,
            String passwordC) {
        return password.equals(passwordC);
    }

    public boolean passwordValidation(String password) {
        boolean result = passwordLengthValidation(password)
                && passwordLengthValidation(password);
        return result;
    }
}
